#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""

@author: erayturkel
"""
from gensim.test.utils import common_corpus, common_dictionary
from gensim.models.wrappers import DtmModel
import os
from gensim import corpora, utils
from gensim.corpora import Dictionary, bleicorpus
import numpy as np
from gensim.matutils import hellinger, Sparse2Corpus,Scipy2Corpus
import scipy
import scipy.io
import pandas as pd

foldername="XXXXXXXX"
#Set path to dynamic topic model binaries
path_to_dtm_binary = 'XXXXXXXX'
#Set path to newspaper corpus (in blei corpus format) ordered according to time
path_to_corpus='XXXXXXXX'
corpus_dfm=scipy.io.mmread(path_to_corpus)
gensim_corpus_file=Sparse2Corpus(corpus_dfm,documents_columns=False)
#Set path to time slice file: a csv with two columns.
#One column representing months, and another column with the number of articles on that month
path_to_timeslices='XXXXXXXX'
time_slices =pd.read_csv(path_to_timeslices,sep=',')
time_slice_monthly=np.array(time_slices['column_name'])
vocab_list=Dictionary.from_corpus(gensim_corpus_file)
dim_model = DtmModel(path_to_dtm_binary, corpus=gensim_corpus_file,
                     id2word=vocab_list,time_slices=time_slice_monthly,
                     num_topics=8, model='fixed',initialize_lda=True)
#Path to save the model
path_to_save='XXXXXXXX'
dim_model.save(path_to_save)
modelinf = [item for items in dim_model.influences_time for item in items]
#Path to save the influence scores
path_to_save_inf='XXXXXXXX'
np.savetxt(path_to_save_inf, modelinf, delimiter=",")



